package cz.fit.vutbr.pis2012.augeaswh.control.ekonom.orders;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import cz.fit.vutbr.pis2012.augeaswh.managers.OrderedItemsManager;
import cz.fit.vutbr.pis2012.augeaswh.managers.OrdersManager;
import cz.fit.vutbr.pis2012.augeaswh.persistence.Order;
import cz.fit.vutbr.pis2012.augeaswh.persistence.OrdersStockType;

@ManagedBean
@SessionScoped
public class OrdersBean implements Serializable {
	private static final long serialVersionUID = -2842854143755533645L;
	@EJB
	private OrdersManager om;
	@EJB
	private OrderedItemsManager oim;
	private int page;
	private final int recordsPerPage;
	private Order currentSupplier;

	public OrdersBean() {
		this.page = 1;
		this.recordsPerPage = 15;
		this.currentSupplier = null;
	}

	public List<Order> getOrders() {
		return om.getOrders();
	}

	public String editOrder() {
		return "edit";
	}
	
	public String addItem() {
		return "add_item";
	}
	
	public int getPage() {
		return this.page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRecordsPerPage() {
		return this.recordsPerPage;
	}

	public Order getCurrentSupplier() {
		return currentSupplier;
	}

	public void setCurrentSupplier(Order currentSupplier) {
		this.currentSupplier = currentSupplier;
	}
	
	public int getOrderedItemsCount(Order order) {
		return oim.getOrderedItemsCount(order);
	}
	
	public BigDecimal getOrderedItemsAmountSum(Order order) {
		return oim.getOrderedItemsAmountSum(order);
	}
	
	public BigDecimal getOrderedItemsPriceSum(Order order) {
		return oim.getOrderedItemsPriceSum(order);
	}
	
	public List<OrdersStockType> getOrderedItems(Order o) {
		return oim.getOrderedItems(o);
	}
	
	public void deleteOrderedItem(OrdersStockType ost)  {
		oim.delete(ost);
	}
}
